package com.efounder.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.view.View;
import android.widget.TextView;
import com.efounder.adapter.OrderAdapter;
import com.efounder.bean.WinTreasureDetailsBean;
import com.efounder.mobilemall.R;
import com.efounder.presenter.MallWinTreasureDetailsPresenter;
import com.efounder.util.DialogUtil;
import com.efounder.mvp.base.MvpBaseActivity;


/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2018/11/2 10:18
 * @desc : 夺宝结果界面
 * @version: 1.0
 */
public class MallWinTreasureDetailsActivity extends MvpBaseActivity<MallWinTreasureDetailsPresenter> {

    /**
     * 标题
     */
    TextView tvTitle;
    /**
     * 售馨时间，售馨区块号，幸运区块号，幸运区块哈希，夺宝夺宝总人数，
     * 本期幸运号码，10进制转换value，取余，夺宝总人次，幸运号码
     */
    TextView tvSelloutTime;
    TextView tvSelloutBlockNo;
    TextView tvLuckyBlockNo;
    TextView tvLuckyBlockHash;
    TextView tvSunNum;
    TextView tvPeriodLuckyNum;
    TextView tvTenConversion;
    TextView tvRemainder;
    TextView tvPeriodTotal;
    TextView tvBottomLuckyNum;
    /**
     * 底部转10进制key
     */
    TextView tvTenConversionKey;
    ConstraintLayout clContent;
    TextView tvWinHint;
    /**
     * 商城商品id
     */
    private String mallGoodsId;

    /**
     * 订单状态  是否中奖
     */
    private String orderStatus;

    public MallWinTreasureDetailsActivity() {
    }

    public static void start(Context context, String mallGoodsId, String orderStatus) {
        Intent starter = new Intent(context, MallWinTreasureDetailsActivity.class);
        starter.putExtra("mallGoodsId", mallGoodsId);
        starter.putExtra("orderStatus", orderStatus);
        context.startActivity(starter);
    }

    @Override
    protected MallWinTreasureDetailsPresenter initPresenter() {
        return new MallWinTreasureDetailsPresenter(this);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_treasure_result;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvSelloutTime = (TextView) findViewById(R.id.tv_sellout_time);

        tvSelloutBlockNo = (TextView) findViewById(R.id.tv_sellout_block_no);

        tvLuckyBlockNo = (TextView) findViewById(R.id.tv_lucky_block_no);

        tvLuckyBlockHash = (TextView) findViewById(R.id.tv_lucky_block_hash);

        tvSunNum = (TextView) findViewById(R.id.tv_sun_num);

        tvPeriodLuckyNum = (TextView) findViewById(R.id.tv_period_lucky_num);

        tvTenConversion = (TextView) findViewById(R.id.tv_ten_conversion);

        tvRemainder = (TextView) findViewById(R.id.tv_remainder);

        tvPeriodTotal = (TextView) findViewById(R.id.tv_period_total);

        tvBottomLuckyNum = (TextView) findViewById(R.id.tv_bottom_lucky_num);
        /**
         * 底部转10进制key
         */
        tvTenConversionKey = (TextView) findViewById(R.id.tv_ten_conversion_key);
        clContent = (ConstraintLayout) findViewById(R.id.cl_content);
        tvWinHint = (TextView) findViewById(R.id.tv_win_hint);
        mallGoodsId = getIntent().getStringExtra("mallGoodsId");
        orderStatus = getIntent().getStringExtra("orderStatus");
        tvTitle.setText(getString(R.string.mall_win_treasure_details_title));
    }

    @Override
    protected void initData() {

        presenter.getWinTreasureDetailsBean(mallGoodsId);
    }

    @Override
    public void initEvent() {

    }

    /**
     * 获取详情数据成功
     *
     * @param winTreasureDetailsBean 数据实体类
     */
    public void getWinTreasureDetailsBeanDataSuccess(WinTreasureDetailsBean winTreasureDetailsBean) {
        clContent.setVisibility(View.VISIBLE);
        tvSelloutTime.setText(winTreasureDetailsBean.getData().getGoodsWinner().getSellOutBlockTime());
        tvSelloutBlockNo.setText(winTreasureDetailsBean.getData().getGoodsWinner().getSellOutBlock());
        tvLuckyBlockHash.setText(getString(R.string.mall_win_treasure_details_lucky_block_hash_value,
                winTreasureDetailsBean.getData().getGoodsWinner().getLuckyHash()));
        tvLuckyBlockNo.setText(winTreasureDetailsBean.getData().getGoodsWinner().getLuckyBlock());
        tvSunNum.setText(winTreasureDetailsBean.getData().getGoodsWinner().getTotal() + "");
        tvPeriodLuckyNum.setText(winTreasureDetailsBean.getData().getGoodsWinner().getWinnerId() + "");
        tvTenConversion.setText("( " + winTreasureDetailsBean.getData().getGoodsWinner().getLuckyHashDecimal());
        tvRemainder.setText("%");
        tvPeriodTotal.setText(winTreasureDetailsBean.getData().getGoodsWinner().getTotal() + " )");
        tvBottomLuckyNum.setText(winTreasureDetailsBean.getData().getGoodsWinner().getWinnerId() + "");
        tvTenConversionKey.setText(getString(R.string.mall_win_treasure_details_ten_conversion, winTreasureDetailsBean.getData().getGoodsWinner().getLuckyHash()));

        if (orderStatus.equals(OrderAdapter.SNATCH_WIN)) {
            tvWinHint.setText(R.string.mall_win_treasure_order_details_result_success_hint);
        } else {
            tvWinHint.setText(R.string.mall_win_treasure_order_details_result_fails_hint);
        }
    }

    /**
     * 获取信息失败
     */
    public void getWinTreasureDetailsBeanDataFails() {
        //隐藏主布局内容  弹窗提醒
        clContent.setVisibility(View.GONE);
        DialogUtil.showDialogNoCancel(activity, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }, R.string.common_text_hint, activity.getString(R.string.mall_win_treasure_order_details_result_hint)
                , activity.getString(R.string.mail_sure));
    }
}
